﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    class TyGiaDAO
    {
        public static List<TyGiaDTO> XemTyGia()
        {
            List<TyGiaDTO> l = new List<TyGiaDTO>();
            TyGiaDTO loai = null;
            SqlConnection cn = DataProvider.Connect();
            SqlCommand cmd = new SqlCommand("Proc_TyGia_XemTyGia", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            //cmd.Parameters.Add(new SqlParameter("@ma", maID));
            SqlDataReader dataReader = cmd.ExecuteReader();
            if (dataReader.Read())
            {
                loai = new TyGiaDTO();
                loai.ChuyenKhoan = Convert.ToInt32(dataReader["ChuyenKhoan"]);
                loai.GiaBan = Convert.ToSingle(dataReader["GiaBan"]);
                loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
                loai.IDNVCapNhat = Convert.ToInt32(dataReader["IDNVCapNhat"]);
                loai.IDNgayVanDung = Convert.ToInt32(dataReader["IDNgayVanDung"]);
                loai.MaLoaiTien = Convert.ToInt32(dataReader["MaLoaiTien"]);
                loai.Sec = Convert.ToSingle(dataReader["Sec"]);
                
            }
            cn.Close();
            return l;
        }

        public static List<TyGiaDTO> SuaTyGia()
        {
            List<TyGiaDTO> l = new List<TyGiaDTO>();
            TyGiaDTO loai = null;
            SqlConnection cn = DataProvider.Connect();
            SqlCommand cmd = new SqlCommand("Proc_TyGia_Update", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dataReader = cmd.ExecuteReader();
            if (dataReader.Read())
            {
                loai = new TyGiaDTO();
                loai.ChuyenKhoan = Convert.ToInt32(dataReader["ChuyenKhoan"]);
                loai.GiaBan = Convert.ToSingle(dataReader["GiaBan"]);
                loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
                loai.IDNVCapNhat = Convert.ToInt32(dataReader["IDNVCapNhat"]);
                loai.IDNgayVanDung = Convert.ToInt32(dataReader["IDNgayVanDung"]);
                loai.MaLoaiTien = Convert.ToInt32(dataReader["MaLoaiTien"]);
                loai.Sec = Convert.ToSingle(dataReader["Sec"]);

            }
            cn.Close();
            return l;
        }

    }
}
